package com.yunhe.authority.repository.paymentInfo;

import com.yunhe.authority.domain.company.WaterElectricityCost;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;


/**
 * @ClassName: WaterElectricityCostRepository
 * @Description:
 * @author: GongDaCheng
 * @Date: 10:12 2021/7/16
 */
@Repository
public interface WaterElectricityCostRepository extends Neo4jRepository<WaterElectricityCost, Long> {

    /**
     * @Description 根据企业id查询企业水电缴费信息
     * @Param Long companyId
     * @Return WaterElectricityCost
     * @Date 2021/7/16 10:18
     */
    @Query("match (c:Company)-[r:HAS_WATER_ELECTRICITY_COST]->(wec:WaterElectricityCost) where ID(c)={companyId} return wec")
    WaterElectricityCost getByCompanyId(@Param("companyId") Long companyId);

    /**
     * @Description 企业水电缴费信息绑定企业
     * @Param Long companyId, Long id
     * @Return
     * @Date 2021/7/16 10:23
     */
    @Query("match (c:Company),(wec:WaterElectricityCost) where ID(c) = {companyId} and ID(wec) = {id} create (c)-[r:HAS_WATER_ELECTRICITY_COST]->(wec)")
    void bindCompany(@Param("companyId") Long companyId, @Param("id") Long id);

    /**
     * @Description 根据企业id解绑并删除企业水电缴费信息
     * @Param Long companyId
     * @Return
     * @Date 2021/8/17 17:44
     */
    @Query("match (c:Company)-[r:HAS_WATER_ELECTRICITY_COST]->(wec:WaterElectricityCost) where ID(c)={companyId} delete r, wec")
    void unbindAndDelete(@Param("companyId") Long companyId);
}
